'use strict';

const fs = require('fs');
const { errors } = require('../index');
module.exports = async path => {
  const [ err ] = await fs.promises.access(path)
    .then(res => [ null, res ])
    .catch(err => [ err ]);
  if (err) {
    await fs.promises.mkdir(path);
  }

  const data = {};
  Object.values(errors)
    .forEach(error => {
      data[error.code] = error.message;
    });

  const ret = fs.promises.writeFile(`${path}/errors.json`, JSON.stringify(data, null, 2));
  return ret;
};
